package messages;

import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import utils.Serialization;
import utils.XmlSerializationUtils;
import connection.exception.ConnectionResetException;

public class SignatureValidationRequestMessage implements Convertible {

    private static final long serialVersionUID = 1L;
    
    public String _document;
    
    public String _signatureStruct;

    public SignatureValidationRequestMessage() {}
     
    public SignatureValidationRequestMessage(String document, String signatureStruct) {
        _document = document;
        _signatureStruct = signatureStruct;
    }
    
    @Override
    public Element convertToCanonic(Document doc) {
        
        String className = getClass().getSimpleName();
        
        Element el = doc.createElement(className);

        if (_document != null) {
            Element childEl = doc.createElement("Document");
            childEl.setTextContent(_document);
            el.appendChild(childEl);

        }
        
        if (_signatureStruct != null) {
            Element childEl = doc.createElement("SignatureStructure");
            childEl.setTextContent(_signatureStruct);
            el.appendChild(childEl);

        }

        return el;
    } 


    @Override
    public Object convertFromCanonic(Element el) {
        this._document = XmlSerializationUtils.getTextValue(el, "Document");
        this._signatureStruct = XmlSerializationUtils.getTextValue(el, "SignatureStructure");
        return this;
    }

    public static void main(String[] args) throws ConnectionResetException, IOException{

        SignatureValidationRequestMessage gen = new SignatureValidationRequestMessage();
        gen._document = "dasdas";
        gen._signatureStruct = "wdasdddsadawe";

        byte[] serialized = Serialization.Serialize(gen);

        Object newGen = Serialization.Deserialize(serialized);

        newGen.toString();

        System.in.read();
    }
}

